<!--
 * @Description: 结算确认
 * @Author: wangwangwang
 * @Date: 2020-09-21 14:09:06
 * @LastEditors: Please set LastEditors
 * @LastEditTime: 2021-12-29 14:35:56
-->
<template>
  <div class="pages_content table">
    <el-container>
      <el-header>
        <breaDcrumb />
      </el-header>
      <el-main>
        <div class="header_right" @click="showCardNav = !showCardNav">
          <div class="title">搜索</div>
          <div>
            <div :class="{ 'arrowTransform': !showCardNav, 'arrowTransformReturn': showCardNav}">
              <i style="margin-right: 5px" class="el-icon-arrow-down"></i>
            </div>
          </div>
        </div>
        <div v-show="showCardNav" class="hr"></div>
        <el-collapse-transition>
          <div v-show="showCardNav">
            <div class="search">
              <span style="display: inline-block;margin-bottom: 10px;">
                <span style="margin-right: 12px;">结算单号</span>
                <el-input v-model="tableParam.settlementNo" style="width: 220px;" clearable placeholder="请输入" @keyup.enter.native="gettableData()" />
              </span>
              <span style="margin-left: 24px;">
                <span style="margin-right: 12px;">状态</span>
                <el-select v-model="tableParam.dataStatus" style="width: 220px;" placeholder="请选择">
                  <el-option label="通过" :value="2"></el-option>
                  <el-option label="未审核" :value="1"></el-option>
                  <el-option label="拒绝" :value="3"></el-option>
                </el-select>
              </span>
              <el-button icon="el-icon-search" size="medium" class="bottom_all but1" @click="(tableParam.page = 1), gettableData()">查 询</el-button>
              <el-button size="medium" class="bottom_all_two" style="margin-left:12px;" @click="init()">重 置</el-button>
            </div>
          </div>
        </el-collapse-transition>
        <div class="hr"></div>
        <div class="card">
          <div v-loading="tableLoading" class="card_info" :style="style">
            <el-table :header-cell-style="{ background: '#f3f6f9' }" :cell-style="{ borderRight: 'none' }" border stripe style="width:100%" :data="tableData" tooltip-effect="dark" @selection-change="handleSelectionChange">
              <template v-for="(item, index2) in table">
                <el-table-column v-if="item.status" :key="index2" :label="item.label" align="center" :width="item.width">
                  <template slot-scope="scope">
                    <span v-if="item.label == '状态'" style="color:#969799;">
                      <span v-if="scope.row.dataStatus==1">未审核</span>
                      <span v-if="scope.row.dataStatus==2">通过</span>
                      <span v-if="scope.row.dataStatus==3">拒绝</span>
                    </span>
                    <el-button v-else-if="item.label == '操作'&&ButtonList.findIndex(res=>(res.buttonValue=='CHAKAN'))!==-1" size="mini" class="bottom_one" @click="show(scope.row)">查看</el-button>
                    <span v-else>{{ scope.row[item.prop] }}</span>
                  </template>
                </el-table-column>
              </template>
            </el-table>
          </div>
        </div>
      </el-main>
      <div class="card_bottom">
        <div class="card_bottom_left">
          <div class="top_page_totle">总共{{ total }}条</div>
          <el-pagination :current-page.sync="tableParam.page" :page-size="tableParam.pageSize" :page-sizes="[10, 20, 30, 40,50,100,200,500,1000]" layout="prev,pager,sizes,next,jumper" :total="total" @size-change="sizeChange" @current-change="gettableData()"></el-pagination>
        </div>
        <div>
          <el-button size="mini" icon="el-icon-refresh-right" class="bottom_all_two" @click="gettableData">刷新</el-button>
        </div>
      </div>
    </el-container>
    <el-dialog v-dialogDrag :visible.sync="activedialog" width="680px" :close-on-click-modal="false">
      <span slot="title" class="dialog-title">异常处理</span>
      <div class="dialoginfo">
        <div class="textline">
          <div class="left">异常现象：</div>
          <div class="right">{{results.phenomena}}</div>
        </div>
        <div class="textline">
          <div>原因：</div>
          <div>{{results.cause}}</div>
        </div>
        <div class="textline">
          <div>拟处理方式：</div>
          <div>{{results.processMode}}</div>
        </div>
        <div class="textline">
          <div>条件接收方式：</div>
          <div>{{results.acceptableConditings}}</div>
        </div>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button class="bottom_all_two" @click="activedialog = false">取 消</el-button>
      </span>
    </el-dialog>
    <!-- 原物料结算查看 -->
    <el-dialog v-dialogDrag :visible.sync="billDeta1" width="1180px" :close-on-click-modal="false">
      <span slot="title" class="dialog-title">原物料结算单</span>
      <div ref="html" style="padding:10px 20px">
        <div class="bill_top">
          <span style="margin-right:40px;"><span class="text">供应商：</span>{{billDetails1.supplier}}</span>
          <span style="margin-right:40px;"><span class="text">结算时间段：</span>{{billDetails1.startTime}}至{{billDetails1.endTime}}</span>
          <span><span class="text">结算单编号：</span>{{billDetails1.statementNo}}</span>
        </div>
        <div style="padding:10px 0">
          <span style="color: #ff0000">公司:</span>
          <span style="padding-left:15px;padding-right:40px">{{billDetails1.company}}</span>
          <span style="color: #ff0000">站点名称:</span>
          <span style="padding-left:15px">{{billDetails1.stationName}}</span>
        </div>
        <div class="bill_title1" style="padding-bottom: 15px;">结算信息</div>
        <el-table v-if="billDetails1.list" :header-cell-style="{ background: '#f3f6f9' }" :cell-style="{ borderRight: 'none'}" border stripe style="width: 100%" :data="billDetails1.list" tooltip-effect="dark">
          <el-table-column label="开票单位" align="center" prop="cooperativeUnit" width="120"></el-table-column>
          <el-table-column label="结算物料" align="center" prop="rawName" width="120"></el-table-column>
          <el-table-column label="时间段" align="center" width="360">
            <template slot-scope="scope">
              {{scope.row.startTime}}至{{scope.row.endTime}}
            </template>
          </el-table-column>
          <el-table-column label="站点" align="center" prop="receiveStation" width="120"></el-table-column>
          <el-table-column label="单价（元）" align="center" prop="statementUnitPrice" width="120"></el-table-column>
          <el-table-column label="收货量" align="center" prop="receiveNum" width="120"></el-table-column>
          <el-table-column label="结算单价（元）" align="center" width="120" prop="statementUnitPrice">
          </el-table-column>
          <el-table-column label="结算量（吨）" align="center" width="120" prop="statementNum">
          </el-table-column>
          <el-table-column label="应付金额（元）" align="center" prop="dealPrice" width="120">
          </el-table-column>
          <el-table-column label="扣减金额（元）" align="center" width="120" prop="deductAmount">
          </el-table-column>
          <el-table-column label="增加金额（元）" align="center" width="120" prop="increaseAmount">
          </el-table-column>
          <el-table-column label="结算金额（元）" align="center" width="120" prop="dealPrice">
          </el-table-column>
          <el-table-column label="扣减/增加金额备注" align="center" width="220" prop="remark">
          </el-table-column>
        </el-table>
        <div v-if="billDetails1.list" class="combined">小计：{{combined(billDetails1.list)}}</div>
        <!-- 结算补差 -->
        <div class="bill_title">结算补差</div>
        <el-table :header-cell-style="{ background: '#f3f6f9' }" :cell-style="{ borderRight: 'none' }" border stripe style="width: 100%" :data="billDetails1.compensateList" tooltip-effect="dark">
          <el-table-column label="开票单位" align="center" prop="cooperativeUnit"></el-table-column>
          <el-table-column label="物料名称" align="center" prop="rawName"></el-table-column>
          <el-table-column label="补差日期" align="center">
            <template slot-scope="scope">
              {{scope.row.compensateStartTime+'-'+scope.row.compensateEndTime}}
            </template>
          </el-table-column>
          <el-table-column label="补差数量" align="center" prop="compensateNum">
          </el-table-column>
          <el-table-column label="补差单价（元）" align="center" prop="compensatePrice">
          </el-table-column>
          <el-table-column label="补差金额（元）" align="center" prop="compensateAmount">
          </el-table-column>
        </el-table>
        <div class="bill_title">扣减金额</div>
        <el-table :header-cell-style="{ background: '#f3f6f9' }" :cell-style="{ borderRight: 'none' }" border stripe style="width: 100%" :data="deductionList" tooltip-effect="dark">
          <el-table-column label="协作单位" align="center" prop="cooperativeUnit">
          </el-table-column>
          <el-table-column label="站点" align="center" prop="station">
          </el-table-column>
          <el-table-column label="扣减类型" align="center" prop="deductionType">
          </el-table-column>
          <el-table-column label="扣减金额" align="center" prop="deduction">
          </el-table-column>
          <el-table-column label="是否影响开票" align="center">
            <template slot-scope="scope">
              <el-radio-group v-model="scope.row.influenceInvoice" disabled>
                <el-radio :label="1">是</el-radio>
                <el-radio :label="0">否</el-radio>
              </el-radio-group>
            </template>
          </el-table-column>
          <el-table-column label="备注" align="center" prop="remark">
          </el-table-column>
        </el-table>
        <div class="bill_title">结算合计</div>
        <el-table :header-cell-style="{ background: '#f3f6f9' }" :cell-style="{ borderRight: 'none' }" border stripe style="width: 100%" :data="billDetails1.totalList" tooltip-effect="dark">
          <el-table-column label="开票单位" align="center" prop="cooperativeUnit"></el-table-column>
          <el-table-column label="结算金额（元）" align="center" prop="settlementAmount"></el-table-column>
          <el-table-column label="补差金额（元）" align="center" prop="compensateAmount"></el-table-column>
          <el-table-column label="扣减金额（元）" align="center" prop="deduction"></el-table-column>
          <el-table-column label="实付金额（元）" align="center" prop="realPay"></el-table-column>
          <el-table-column label="票面调整（元）" align="center" prop="faceAdjustment">
          </el-table-column>
        </el-table>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button class="bottom_all_two" @click="billDeta1=false">关闭</el-button>
        <el-button v-if="low.dataStatus==1" class="bottom_all" style="margin-left: 24px" @click="clientupdateStatusFun(low)">确认签收</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import mixin from "@/mixins/ICPSmixin.js";
import {
  queryPage3,
  Download2,
  clientupdateStatus,
} from "@/api/GHnumber/goods.js";
import { get_statement_detail } from "@/api/wise/material.js";
export default {
  mixins: [mixin],
  data() {
    return {
      low: '',
      billDetails1: { list: [] },
      billDeta1: false,
      deductionList: [],
      startTimDateEndTimDate: [],
      /*表格增删改查及下载接口*/
      queryPage: queryPage3,
      DownloadURL: Download2,
      /*表格数据*/
      table: [
        { label: "结算单号", width: "", prop: "settlementNo", status: true },
        { label: "结算时间段", width: "", prop: "times", status: true },
        { label: "提交时间", width: "", prop: "createTime", status: true },
        { label: "状态", width: "", prop: "", status: true },
        { label: "操作", width: "", prop: "", status: true },
      ],
      /*表单页类型，0为无树状，1为有树状，有树状在el-main加上display:flex*/
      pagesType: 0,
      /*添加表单数据*/
      rules: {
        code: [{ required: true, message: "请输入站点编码", trigger: "blur" }],
      },
      fromDate: {
        code: "",
      },
      dialoglist: ["testresult"],
      activedialog: false,
      results: {},
    };
  },
  async created() {
    this.gettableData();
  },
  /*
   *copy(data)深拷贝数据,返回拷贝完的数据
   *gettableData获取列表数据
   *load下载
   *SortNum保持序列号
   * UpdateOrDelete禁用，启用，删除
   * submitFromDate保存更新数据
   */
  methods: {
    clientupdateStatusFun(row) {
      clientupdateStatus({ settlementId: row.settlementId, type: 2, dataStatus: 2 }).then((res) => {
        if (res.code == 1001) {
          this.$message({
            message: '操作成功',
            type: 'success'
          });
          this.billDeta1 = false
          this.gettableData();
        }
      })
    },
    show(low) {
      this.low = low
      get_statement_detail({ statementNo: low.settlementNo }).then(res => {
        if (res.code == 1001) {
          this.billDetails1 = res.data
          let stationName = JSON.parse(res.data.stations).map(res => (res.name))
          this.deductionList = res.data.deductionList
          this.billDetails1.stationName = stationName.join('、')
          this.billDeta1 = true
        }
      })
    },
    downloadLink() {
      this.$Download(this.download, { statementNo: this.low.settlementNo })
    },
    /**结算信息合计*/
    combined(arr) {
      let num = 0
      arr.forEach(res => {
        num = Number(res.dealPrice) - Number(res.deductAmount) + Number(res.increaseAmount) + num
      })
      return num.toFixed(2)
    },
    init() {
      /*重置数据*/
      this.tableParam.dataStatus = "";
      this.tableParam.settlementNo = "";
      this.gettableData();
    },
    sizeChange(value) {
      this.tableParam.pageSize = value;
      this.gettableData();
    },
  },
};
</script>

<style lang="scss" scoped>
.bill_title {
  font-size: 18px;
  font-weight: 600;
  padding: 15px 0;
}
.combined {
  border: 1px solid #ebeef5;
  text-align: center;
  line-height: 40px;
}
.textline {
  line-height: 40px;
  display: flex;
  > div:first-child {
    width: 100px;
    text-align: right;
  }
  > div:last-child {
    width: 500px;
  }
}
.table_link {
  margin-left: 10px;
  color: $bg_color;
}

.table_link:hover {
  opacity: 0.8;
}
.el-input,
.el-select {
  width: 240px;
}
</style>
